//
//  CarReportDefail.m
//  违章查询助手
////  Copyright (c) 2015年 LY. All rights reserved.
//  Created by qianfeng on 15/10/27.

//

#import "CarReportDefail.h"
#import "LXActivity.h"
#import "CarReport.h"
#import "Login.h"
#import "ShareView.h"
@interface CarReportDefail ()<LXActivityDelegate,LoginDelegate>

@end

@implementation CarReportDefail

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];

}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatNav];
    [self creatNavBar];
    webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64)];
    NSURLRequest * request=[NSURLRequest requestWithURL:[NSURL URLWithString:_model.newsurl]];
    webView.delegate=self;
    [self.view addSubview:webView];
    [webView loadRequest:request];
}
-(void)creatNav
{
    UINavigationBar * bar=self.navigationController.navigationBar;
    [bar setBackgroundImage:[UIImage imageNamed:@"custom_dialog_btn_bg"] forBarMetrics:UIBarMetricsDefault];
    [self.view addSubview:bar];
}

-(void)creatNavBar
{
    UIButton * left=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    
    [left setBackgroundImage:[UIImage imageNamed:@"back_normal"] forState:UIControlStateNormal];
    [left addTarget:self action:@selector(leftButton) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftItem=[[UIBarButtonItem alloc]initWithCustomView:left];
    self.navigationItem.leftBarButtonItem=leftItem;
    
    UIButton * right=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];;
    
    [right setBackgroundImage:[UIImage imageNamed:@"btn_share"] forState:UIControlStateNormal];
    [right addTarget:self action:@selector(rightButton) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * rightItem=[[UIBarButtonItem alloc]initWithCustomView:right];
    self.navigationItem.rightBarButtonItem=rightItem;

}

-(void)leftButton
{
    [self dismissViewControllerAnimated:YES completion:nil];
   
}

-(void)rightButton
{
    NSArray * shareButtonTitleArray=@[@"微信",@"朋友圈",@"QQ空间",@"微博"];
 NSArray * shareButtonImageNameArray=@[@"ic_share_weixinmsg",@"ic_share_weixinfriend",@"ic_share_qzone",@"ic_share_weibo"];

   LXActivity * activity = [[LXActivity alloc]initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" ShareButtonTitles:shareButtonTitleArray withShareButtonImagesName:shareButtonImageNameArray];
    [activity showInView:self.view];
}

#pragma mark - LXActivityDelegate
- (void)didClickOnImageIndex:(NSInteger *)imageIndex
{
    
      NSLog(@"点击了分享");
    NSString * access_token=[[NSUserDefaults standardUserDefaults] objectForKey:ACCESS_TOKEN];
    
    //判断是否过期
    if (access_token ==nil || [Help isExpireIn]) {
        Login *login=[[Login alloc]init];
        login.delegate=self;
        UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:login];
        [self presentViewController:nav animated:YES completion:nil];
    }else
    {
        [self pushView];
    
    }
}

-(void)pushView
{
    
    ShareView * share=[[ShareView alloc]initWithNibName:@"ShareView" bundle:nil];
    UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:share];
    
    share.model=_model;
    
    share.block=^(){
        
        UIAlertView * view=[[UIAlertView alloc]initWithTitle: nil message:@"微博发送成功" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [view show];
        [view dismissWithClickedButtonIndex:0 animated:YES];
    };
    
//    [self.navigationController pushViewController:share animated:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)didClickOnCancelButton
{
    NSLog(@"点击了取消按钮");
}

#pragma mark - WebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
  
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
